import base64
import os
import requests
import URL
img = lambda x: base64.b64encode(open(x, "rb").read()).decode()

def face_match(image1, image2):
    response = requests.post(
        url=URL.RL,
        params=URL.Params1,
        headers=URL.Headers,
        json=[{
            'image': img(image1),
            'image_type': "BASE64",
        },
            {'image': img(image2),
             'image_type': "BASE64"}
        ]
    )
    if response.json()["error_msg"] == "pic not has face":
        return False
    return response.json()['result']['score']

folder = os.listdir('人脸比对素材/image')
for i in folder:
    sm = face_match('./人脸比对素材/0.jpg', '人脸比对素材/image/' + i)
    print(f"人脸相似度：{sm:.2f}%")

